package day8;

import java.security.PublicKey;
import java.sql.Statement;

public class Home1 {
    static double total=7000;
    static int speed;
    static String winner=null;
    static int sum=0;
    public static void main(String[] args) throws InterruptedException {
        Climber c1=new Climber("lili",10);
        Climber c2=new Climber("Peter",8);
        c1.start();
        c2.start();
        //demo2();
        //demo1();
        demo3();
       // demo4();
    }

    public static void demo1(){
        Thread t=new Thread(()->{
            double high=100;
            double totalHigh=0;
            for(int i=1;i<=10;i++){
                totalHigh+=high;
                high=high/2;
                if(i<10){
                    totalHigh+=high;
                }
            }
            System.out.println("小球在第十次落地一共经过"+totalHigh+"米");
            System.out.println("小球在第十次反弹"+high);
        });
        t.start();
        //System.out.println();
    }
    public static void demo2() throws InterruptedException {

        Thread t1=new Thread(()->{
            String name1=Thread.currentThread().getName();
            while (!Thread.currentThread().isInterrupted()){
                //检查当前线程是否被中断isInterrupted()
                try {
                    Thread.sleep(10);
                    System.out.println(name1+"sum"+sum);
                    sum++;
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();//重新设置中断
                }
            }
        },"A线程");
        Thread t2=new Thread(()->{
            String name2=Thread.currentThread().getName();
            while (!Thread.currentThread().isInterrupted()){
                try {
                    Thread.sleep(20);
                    System.out.println(name2+"sum"+sum);
                    sum++;
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            }
        },"B线程");
        t1.start();
        t2.start();
        Thread.sleep(3000);
        t1.interrupt();//3s后t1 t2被中断
        t2.interrupt();
        t1.join();
        t2.join();
        System.out.println("持续3s后的sum为"+sum);

    }
    public static void demo3() throws InterruptedException {
        Thread A=new Thread(()->{
            //String name3=Thread.currentThread().getName();
            System.out.println(Thread.currentThread().getName());
        },"A");
        Thread B=new Thread(()->{
            //String name4=Thread.currentThread().getName();
            System.out.println(Thread.currentThread().getName());
        },"B");
        Thread C=new Thread(()->{
            //String name4=Thread.currentThread().getName();
            System.out.println( Thread.currentThread().getName());
        },"C");
        A.start();
        A.join();
        B.start();
        B.join();
        C.start();
        C.join();
    }
    public static void demo4(){


    }
}
class Climber extends Thread{
    double road=0;//初始的路程
    int speed;//速度
    public Climber() {
    }
    public Climber(String name, int speed) {
        super(name);
        this.speed = speed;
    }

    public void run() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        road+=speed;
        if(road%100==0){
            System.out.println();
        }

    }
}
